package com.dattplace.task;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.dattplace.model.ShareTimes;
import com.dattplace.service.IShareService;
import com.dattplace.util.DateUtil;
import com.dattplace.util.PropertiesUtil;

@Component
public class ViewCountTask {

	@Autowired
	private IShareService shareService;
	
	private static final Logger logger = Logger.getLogger(ViewCountTask.class);
	//  获取所有帖子
	private static final PropertiesUtil propertiesUtil = new PropertiesUtil("config.properties");
		
	/*@Scheduled(cron = "0/5 * *  * * ?")*/
	@Scheduled(cron = "0 15 7 * * ?")
	public void increaseReadCount() {

		logger.info("------------------- 开始执行定时任务 ----------------------");
		
		int week =DateUtil.getWeekOfDate(new Date());
		
		List<ShareTimes> list =shareService.shareList();
		if(!CollectionUtils.isEmpty(list)){
			for(ShareTimes s :list){
				//  增加点赞数
				java.util.Random random=new java.util.Random();// 定义随机类
				int result=random.nextInt(10)+1;// 返回[0,9)集合中的整数，注意不包括10
				
				//  增加点赞数
				java.util.Random random1=new java.util.Random();// 定义随机类
				int result1=random1.nextInt(50);// 返回[0,49)集合中的整数，注意不包括10
							
				if(week==5 || week==6){
					result =random.nextInt(30)+20;
					result1 =random1.nextInt(200)+300;
				}
				shareService.increasePraiseCount(s.getShareId(),result);
				// 视频增加阅读数
				if(s.getShareType()==1){
					shareService.increaseReadCount(s.getShareId(),result1+50);
				}
			}
		}
		logger.info("------------------- 结束执行定时任务 ----------------------");
		
	}
}
